﻿@using OperationPlugins.WebApp.Views
@using PerpetuumSoft.Knockout

@model OperationPlugins.WebApp.ViewModes.ApplicationsViewModel
@{
    var ko = Html.CreateKnockoutContext();
}


<div class="page-header">
    <h1>APPLICATIONS <small></small></h1>
</div>

<div class="panel panel-default">
    <div class="panel-heading">Application server status</div>
    <div class="panel-body">
        <div class="col-lg-12">
            <div class="col-lg-2">Current status:</div>
            <div class="col-lg-10"><strong>@ko.Html.Span(x => x.Status)</strong></div>
        </div>

        <div class="col-lg-12 op-gap-normal"></div>

        <div class="col-lg-12">
            <div class="col-lg-2"></div>
            <div class="col-lg-3">
                @ko.Html.ButtonWithImage("Start application server", "Admin", "StartApplicationServer", "fa fa-play fa-fw", new { @class = "btn btn-default" }).Enable(x => x.IsStartEnabled)
            </div>
            <div class="col-lg-1"></div>
            <div class="col-lg-3">
                @ko.Html.ButtonWithImage("Recycle installed applications", "Admin", "RecycleInstalledApplications", "fa fa-recycle fa-fw", new { @class = "btn btn-default" }).Enable(x => x.IsRecycleEnabled)
            </div>

        </div>
        <div class="col-lg-12 op-gap-small"></div>
        <div class="col-lg-12">
            <div class="col-lg-2"></div>
            <div class="col-lg-3">
                @ko.Html.ButtonWithImage("Stop application server", "Admin", "StopApplicationServer", "fa fa-stop fa-fw", new { @class = "btn btn-default" }).Enable(x => x.IsStopEnabled)
            </div>
        </div>

    </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">Installed applications</div>
    <div class="panel-body">
        <table class="table table-striped table-hover ">
            <thead>
                <tr>
                    <th></th>
                    <th>AppId</th>
                    <th>Name</th>
                    <th>Version</th>
                    <th>Services</th>
                    <th>Status</th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @using (var application = ko.Foreach(x => x.InstalledApplications))
                {
                    @application.Html.TrBegin(application).Css("danger", x => x.IsBroken)
                    @application.Html.Td("Preferences", "Admin", "ApplicationPreferences", "fa fa-cog", application, new { index = "$index()" }, new { @class = "app-td-image-link" })
                    @application.Html.Td(x => x.AppId, application)
                    @application.Html.Td(x => x.Name, application)
                    @application.Html.Td(x => x.Version, application)
                    @application.Html.Td(x => x.Services, application)
                    @application.Html.Td(x => x.Status, application)
                    @application.Html.Td("Start", "Admin", "StartApplication", "fa fa-play", application, new { index = "$index()" }, new { @class = "app-td-image-link" }).Enable(x => x.IsStartEnabled)
                    @application.Html.Td("Stop", "Admin", "StopApplication", "fa fa-stop", application, new { index = "$index()" }, new { @class = "app-td-image-link" }).Enable(x => x.IsStopEnabled)
                    @application.Html.Td("Recycle", "Admin", "RecycleApplication", "fa fa-recycle", application, new { index = "$index()" }, new { @class = "app-td-image-link" }).Enable(x => x.IsRecycleEnabled)
                    @application.Html.Td("Uninstall", "Admin", "UninstallApplication", "fa fa-remove", application, new { index = "$index()" }, new { @class = "app-td-image-link" }).Enable(x => x.IsUninstallEnabled)
                    @application.Html.TrEnd(application)
                }
            </tbody>
        </table>
        
        <div class="col-lg-12">
            @ko.Html.ButtonWithImage("Export installation...", "Admin", "ExportInstallation", "fa fa-cloud-download fa-fw", new { @class = "btn btn-default pull-right", @style = "margin-left: 8px;" }).Enable(x => x.IsStopEnabled)
            @ko.Html.ButtonWithImage("Install new application...", "Admin", "InstallNewApplication", "fa fa-cloud-upload fa-fw", new { @class = "btn btn-default pull-right" }).Enable(x => x.IsStopEnabled)
        </div>
        <div class="col-lg-12 op-gap-small"></div>
        <div class="col-lg-12">
        </div>

        @using (ko.If(x => x.InstalledApplications.Count == 0))
        {
            <div class="col-lg-12" style="text-align: center">
                <small class="text-muted"><em>No installed applications available!</em></small>
            </div>
        }
    </div>
</div>

@ko.Init(Model)